Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

window-resize-subject

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

window-resize-subject

[![npm version](https://badge.fury.io/js/window-resize-subject.svg)](https://badge.fury.io/js/window-resize-subject) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) ![CI](https://github.com/mya-ak

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
decreased by-29.65%
Maintainers
1
Weekly downloads
 
Created
Source

window-resize-subject

npm version License: MIT CI

Handler for the window resize event of the observer pattern.

Install

npm

$ npm i window-resize-subject

yarn

$ yarn add window-resize-subject

Usage

import { WindowResizeSubject } from 'window-resize-subject';

// create subject
const subject = new WindowResizeSubject();

// add observer
const observer = ({ width, height }) => {
  // do something
};
subejct.addObserver('name', observer);

// start watching the resize event
subject.subscribe();

note: You can also write in a method chain

subejct.addObserver('name', observer).subscribe();

Methods

addObserver

  • params:
    • name:
      • type: string | Symbol
    • observer:
      • type: WindowResizeObserver
        • details: (event: { width: number, height: number }) => void

Add observer.
And called with the current window size.

subejct.addObserver('name', ({ width, height }) => {
  // do something
});

subscribe

Start watching the resize event.

unsubscribe

Stop watching the resize event.

note: observer is not deleted.

notifyObservers

  • params:
    • size:
      • type: Object
        • width: number
        • height: number

Force update.

subject.notifyObservers({ width: 800, height: 600 });

deleteObserver

  • params:
    • name:
      • type: string | Symbol

Deletes the specified Observer.

subject.deleteObserver('name');

deleteObservers

Deletes all Observers.

setDelay

  • params:
    • type: number

Changes the delay time for a resize event.

subject.setDelay(100);

hasObserver

returns true if it has an observer.

dispatch

Dispatches the current window size.

Options

delay (option)

  • type: number
  • default: 33

Changes the delay time for a resize event.

import { WindowResizeSubject } from 'window-resize-subject';

const subject = new WindowResizeSubject({ delay: 100 });

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT

Keywords

FAQs

Package last updated on 17 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc